import { ref } from 'vue';

export const useCountdown = () => {
    // 倒计时
    const timeNum = ref(60);
    const isSendCode = ref(false);//验证码已发送
    const isSend = ref(false); // 是否展示数字
    let timer:any = ref(null);
    const countdown = () => {
        isSendCode.value = true;
        isSend.value = true;
        timer.value = setInterval(() => {
            timeNum.value--
            if (timeNum.value == 0) {
                timeNum.value = 60;
                isSend.value = false
                clearInterval(timer.value);
            }

        }, 1000)
    };


    return { timeNum, isSendCode, isSend, countdown, timer }
}
